import scrapy
from lxml.html import fromstring

START = "https://baike.baidu.com/item/%E4%B8%AD%E5%9B%BD%E6%AD%8C%E6%9B%B2%E6%8E%92%E8%A1%8C%E6%A6%9C/1072613"


class QuotesSpider(scrapy.Spider):
    name = "singers"
    start_urls = [
        START,
    ]

    def parse(self, response):
        url = response.request.url
        if url == START:
            for singer_link in response.css('b>a'):
                path = singer_link.css('::attr("href")').get()
                yield response.follow(path, self.parse)
        else:
            name = response.css('dl>dd>span>h1::text').get()
            summary = response.css('div.lemma-summary.J-summary').get()
            if summary is None:
                return
            parserObj = fromstring(summary)
            summary_text = str(parserObj.text_content())
            yield {
                'name': name,
                'summary': summary_text,
            }

